package etxt2db.features;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;



public class DictionaryFeatureClassifier extends CharacterFeatureClassifier implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -4304412059917179549L;
	String dictionaryName;
	List<String> dicionario;
	
	public DictionaryFeatureClassifier(String dictionary) throws IOException{
		loadDictionary(dictionary);
		dictionaryName = dictionary;
	}
	
	private void loadDictionary(String dictionary) throws IOException{
		dicionario = new ArrayList<String>();
		BufferedReader in = new BufferedReader(new FileReader(dictionary));
		String str;
		while ((str = in.readLine()) != null) {
			dicionario.add(str);
		}
		in.close();
	}
	
	public List<String> emit(String text) {
		List<String> result = new ArrayList<String>();
		boolean matches = dicionario.contains(text);
		if(matches){
			result.add("matchDictionary_" + dictionaryName + "=" + matches);
		}
		return result;
	}

}
